package br.com.unifebe.tcc.DAO;

import java.util.Collection;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.unifebe.tcc.UTILS.HibernateUtils;
import br.com.unifebe.tcc.model.Cliente;
@SuppressWarnings( "unchecked")
public class ClienteDAO extends DAOimpl<Cliente> {

	private static ClienteDAO instance;
	
	public static ClienteDAO getInstance(){
		if(instance == null){
			instance = new ClienteDAO();
		}
		return instance;
	}
	
	public Cliente getPorId(Long id) {
		Session session = HibernateUtils.getSessionFactory().openSession();
		Cliente cliente = (Cliente) session.load(Cliente.class, id);
		return  cliente;
		
	}
	
	@Override
	public Collection<Cliente> getListaTodos() {
		Session session = HibernateUtils.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		Collection<Cliente> lista = session.createCriteria(Cliente.class).list();
		t.commit();
		return lista;
	}
	
}
